<?
layout("/inc/layout.html",{title:sysTitle}){
?>
<div id="page-wrapper">
		<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
			<div class="page-header pull-left">
				<div class="page-title">订单管理</div>
			</div>
			<div class="clearfix"></div>
		</div>
	<div class="page-content"style="margin-top: -15px;">
		<div class="row mbl" style="height: 100%;">
			<div class="col-lg-12">
				<div class="portlet box">
                    <div class="portlet-body">
                        <div class="table-responsive">
						<div id="example1_wrapper"
							class="dataTables_wrapper form-inline no-footer">
							<div class="row">
								<div class="col-md-12">
									<div id="example1_filter" class="dataTables_filter">
										<label>
											<div class="input-group input-group-sm mbs">
												<span class="input-group-btn" style="font-size: 12px;">
													用户名：
												</span>
												<input type="text"  class="form-control" id="username" name="username" />
											</div>
										</label>
										<label>
											<div class="input-group input-group-sm mbs">
												<span class="input-group-btn" style="font-size: 12px;">
													订单号：
												</span>
												<input type="text" id="orderNumber" class="form-control input-sm">
											</div>
										</label>
										<label>
											<div class="input-group input-group-sm mbs">
												<span class="input-group-btn" style="font-size: 12px;">
													类型：
												</span>
												<select class="form-control" id="type" style="width: 200px;">
													<option value="">全部</option>
													<option value="0">课程</option>
													<option value="1">微课</option>
													<option value="2">直播</option>
												</select>	
											</div>
										</label>
										<label>
											<div class="input-group input-group-sm mbs">
												<span class="input-group-btn" style="font-size: 12px;">
													状态：
												</span>
												<select class="form-control" id="status" style="width: 200px;">
													<option value="">全部</option>
													<option value="0">支付成功</option>
													<option value="1">待支付</option>
												</select>	
											</div>
										</label>
										<label>
											<div class="input-group input-group-sm mbs">
												<span class="input-group-btn" style="font-size: 12px;">
													开始时间：
												</span>
												<input id="startTime" type="text" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" readonly="readonly"/>	
											</div>
										</label>
										<label>
											<div class="input-group input-group-sm mbs">
												<span class="input-group-btn" style="font-size: 12px;">
													结束时间：
												</span>
												<input id="endTime" type="text" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" readonly="readonly"/>	
											</div>
										</label>
										<label>
											<div class="input-group input-group-sm mbs">
												<span class="input-group-btn">
													<button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="get()">查询</button>
												</span>
											</div>
										</label>
									</div>
								</div>
							</div>
							<table style="font-size: 15px;" class="table table-striped table-bordered table-hover dataTable no-footer">
								<thead>
									<tr>
										<th >序号</th>
										<th >订单号</th>
										<th >用户名</th>
										<th >类型</th>
										<th >资源名称</th>
										<th >支付方式</th>
										<th >支付金额</th>
										<th >IP地址</th>
										<th >创建时间</th>
										<th >状态</th>
										<th style="width: 60px;">操作</th>
									</tr>
								</thead>
								<tbody id="findUser">
								</tbody>
							</table>
							<div id="page2" style="text-align: center; margin-top: 20px;"></div>
						</div>
					</div>
                    </div>
                </div>
			</div>
		</div>
	</div>
</div>
<?}?>

<script>
	var curr;
	$(function(){
		demo1();
		layui.use('laydate', function(){
		  var laydate = layui.laydate;
		  //执行一个laydate实例
		  laydate.render({
		     elem: '#startTime' //指定元素
			  ,type: 'datetime'
		  });
		});
		layui.use('laydate', function(){
		  var laydate = layui.laydate;
		  //执行一个laydate实例
		  laydate.render({
		     elem: '#endTime' //指定元素
			  ,type: 'datetime'
		  });
		});
	});
	function get(){
		demo1(1);
	}
	function demo1(cur) {
		$.getJSON("./orderList.do",
			{
				page : cur || 1,
        		orderNumber:$("#orderNumber").val(),
        		type:$("#type").val(),
        		status:$("#status").val(),
        		username:$("#username").val(),
        		startTime:$("#startTime").val(),
        		endTime:$("#endTime").val(),
			},
			function(res) {
				//此处仅仅是为了演示变化的内容
				var str = "";
				for ( var i = 0; i < res.listsize; i++) {
					str += "<tr><td>"
							+ (i + 1)
							+ "</td><td> <label id=>"
							+ res.result[i].orderNumber
							+ "</label></td><td><label >"
							+ res.result[i].username
							+ "</label></td><td><label >";
							if(res.result[i].type='0'){
								str+='课程';
							}else if(res.result[i].type='1'){
								str+='微课';
							}else if(res.result[i].type='2'){
								str+='直播';
							}
							str+= "</label></td><td><label >"
							+ res.result[i].name
							+ "</label></td><td><label >";
							if(res.result[i].payWay=='we_chat'){
								str+='微信支付';
							}else if(res.result[i].payWay=='alipay'){
								str+='支付宝';
							}
							str+= "</label></td><td>"
							+ res.result[i].payPrice
							+ "</label></td><td>"
							+ res.result[i].createIpAddress
							+ "</label></td><td>"
							+ res.result[i].createTime
							+ "</label></td><td>";
							if(res.result[i].status=='0'){
								str+='支付成功';
							}else{
								str+='待支付';
							}
							str+= "</label></td><td>"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"del('"
							+ res.result[i].id
							+ "')\">"
							+ "删除"
							+ "</button>&nbsp;"
							+ "</td></tr>";
				}
				$("#findUser").html(str);

				laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : res.pageSize, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr: cur || 1,
					last: res.pageSize,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							demo1(obj.curr);
			                 curr=obj.curr;
						}
					}
				});
			});
	};
	
	function del(id){
		if (confirm("是否确认删除！！")){
			$.ajax({
					type : "post",
					url : "./orderDel.do",
					data : {
						"id" : id,
					},
					dataType : "json",
					success : function(data) {
						if(data[0].result=='success'){
							demo1();
						}
						layer.msg(data[0].msg);
					},
					error : function(data) {
						alert("请求失败");
					}
				});
		}
	}
</script>